//
//  RootNavigationController.m
//  FinanceBBS
//
//  Created by mibo02 on 2017/12/15.
//  Copyright © 2017年 mibo02. All rights reserved.
//

#import "RootNavigationController.h"

@interface RootNavigationController ()
@end

@implementation RootNavigationController

//APP生命周期中 只会执行一次
+ (void)initialize
{
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setShadowImage:[UIImage new]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationBar setBackgroundImage:[UIImage new]
                 forBarMetrics:UIBarMetricsDefault];
    self.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [self.navigationBar setTintColor:kNavTintColor];
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName :kNavTintColor, NSFontAttributeName : kDefaultFont(17)}];
}

//根视图禁用右划返回
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return self.childViewControllers.count == 1 ? NO : YES;
}

//push时隐藏tabbar
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}
- (void)setAnimatedWithTransition{
    
    CATransition *animation = [CATransition animation];
    //动画时间
    animation.duration = 1.0f;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    //过渡效果
    animation.type = @"pageCurl";
    //过渡方向
    animation.subtype = kCATransitionFromRight;
    [self.view.layer addAnimation:animation forKey:nil];
    //交叉淡化过渡
    animation.type = kCATransitionFade;
    animation.type = kCATransitionPush;
    animation.type = kCATransitionReveal;
    animation.type = kCATransitionMoveIn;
    animation.type = @"cameraIrisHollowOpen";
    animation.type = @"cameraIrisHollowClose";
    //立方体效果
    animation.type = @"cube";
    //收缩效果，如一块布被抽走
    animation.type = @"suckEffect";
    // 页面旋转  -上下翻转效果
    animation.type = @"oglFlip";
    //水波纹
    animation.type = @"rippleEffect";
    //向上翻一页
    animation.type = @"pageCurl";
    //向下翻一页
    animation.type = @"pageUnCurl";
}

/**
 *  返回到指定的类视图
 *
 *  @param ClassName 类名
 *  @param animated  是否动画
 */
-(BOOL)popToAppointViewController:(NSString *)ClassName animated:(BOOL)animated
{
    id vc = [self getCurrentViewControllerClass:ClassName];
    if(vc != nil && [vc isKindOfClass:[UIViewController class]])
    {
        [self popToViewController:vc animated:animated];
        return YES;
    }
    
    return NO;
}

/*!
 *  获得当前导航器显示的视图
 *
 *  @param ClassName 要获取的视图的名称
 *
 *  @return 成功返回对应的对象，失败返回nil;
 */
-(instancetype)getCurrentViewControllerClass:(NSString *)ClassName
{
    Class classObj = NSClassFromString(ClassName);
    
    NSArray * szArray =  self.viewControllers;
    for (id vc in szArray) {
        if([vc isMemberOfClass:classObj])
        {
            return vc;
        }
    }
    
    return nil;
}


-(UIViewController *)childViewControllerForStatusBarStyle{
    return self.topViewController;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
